import React from "react";
import { RegisterCommand, withPropsAPI } from "gg-editor";

class Fullscreen extends React.Component {
  state = { fullscreenClass: "" };

  render() {
    const  that = this;
    const config = {
      // 是否进入列队，默认为 true
      queue: true,
      // 命令是否可用
      enable(/* editor */) {
        return true;
      },

      // 正向命令逻辑
      execute(/* editor */) {
        let {fullscreenClass} = that.state;
        if(fullscreenClass){
          fullscreenClass = ''
        }else{
          fullscreenClass ='flow-fullscrren'
        }
        that.setState({
          fullscreenClass
        },()=>{
          that.props.fullscreen(fullscreenClass)
        })
      },

      // 反向命令逻辑
      back(/* editor */) {
        console.log("执行反向命令");
      },

      // 快捷按键配置
      shortcutCodes: [["metaKey", "n"], ["ctrlKey", "n"]]
    };

    return <RegisterCommand name="fullscreen" config={config} />;
  }
}

export default withPropsAPI(Fullscreen);
